﻿using System.Collections.Generic;
using Coevery.OptionSet.Settings;
using Orchard.ContentManagement;

namespace Coevery.OptionSet.ViewModels {
    public class OptionSetFieldViewModel {
        public int ChildOptionSetId { get; set; }
        public int ParentOptionSetId { get; set; }
        public string ChildName { get; set; }
        public int? ParentSingleTermId { get; set; }
        public string ContainerPart { get; set; }

        public IDictionary<int, List<OptionItemEntry>> GetOptionItemsByParent()
        {
            SortedList<int, List<OptionItemEntry>> result = new SortedList<int, List<OptionItemEntry>>();
            foreach (OptionItemEntry o in OptionItems)
            {
                int parentId = o.Parent_Id;
                if (!result.ContainsKey(parentId))
                {
                    result.Add(parentId, new List<OptionItemEntry>());
                }
                List<OptionItemEntry> optionsList = result[parentId];
                optionsList.Add(o);
            }
            return result;
        }

        #region oldcode
        public string DisplayName { get; set; }
        public OptionSetFieldSettings Settings { get; set; }
        public IList<OptionItemEntry> OptionItems { get; set; }
        public int OptionSetId { get; set; }
        public string Name { get; set; }
        public int? SingleTermId { get; set; }
        #endregion
    }

}
    public class OptionItemEntry {
        //Coevery_OptionSet_OptionItemPartRecord
        public int Parent_Id { get; set; }
        public int Parent_OptionSetId { get; set; }

        public int Id { get; set; }
        public int OptionSetId { get; set; }
        public int Weight { get; set; }
        public bool Selectable { get; set; }
        
        // Vista
        public bool IsChecked { get; set; }
        public string Name { get; set; }

        // X
        public ContentItem ContentItem { get; set; }
    }
